package git.soulbgm.pojo;

import static git.soulbgm.common.Constants.TOPIC_SEND_DATA_PREFIX;

/**
 * 发送数据
 *
 * @author SoulBMG
 * @date 2024-11-10
 */
public class SendData implements Comparable<SendData> {

    private Integer priority;
    private String data;
    private String time;

    public SendData(String topic, String value) {
        String[] split = value.split(" : ");
        if (split.length == 3) {
            this.priority = Integer.parseInt(split[0]);
            data = split[1];
            time = split[2];
        } else if (split.length == 2) {
            String priority = topic.substring(TOPIC_SEND_DATA_PREFIX.length());
            this.priority = Integer.parseInt(priority);
            data = split[0];
            time = split[1];
        }
    }

    public Integer getPriority() {
        return priority;
    }

    public void setPriority(Integer priority) {
        this.priority = priority;
    }

    public String getData() {
        return data;
    }

    public void setData(String data) {
        this.data = data;
    }

    public String getTime() {
        return time;
    }

    public void setTime(String time) {
        this.time = time;
    }

    @Override
    public int compareTo(SendData o) {
        return Integer.compare(o.priority, this.priority);
    }
}
